package com.szxw.BaiduAi.utils;

import org.json.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: 苏执小威
 * @Email:1410511702@qq.com
 * @Desc: 用于关闭流
 * @Date: 2022/9/23 14:33
 */
public class MethodUtils {
    public MethodUtils(){}
    /**
     * 关闭写入流
     * @param resp 响应
     * @param data 调用接口获取的结果
     * @throws IOException
     */
    public static void close(HttpServletResponse resp, Object data) throws IOException {
        PrintWriter writer = resp.getWriter();
        writer.write(data.toString());
        writer.close();
    }

    /**
     * 人脸对比 用于获取图片1
     * @param files
     * @param imageSize1
     * @return
     */
    public static  byte[] image1(byte[] files,Integer imageSize1){
        byte[] file1 = new byte[imageSize1];
        for (int i = 0; i < imageSize1; i++) {
            file1[i] = files[i];
        }
        return file1;
    }
    /**
     *  人脸对比 用于获取图片2
     * @param files
     * @param imageSize2
     * @return
     */
    public static  byte[] image2(byte[] files,Integer imageSize2){
        byte[] file2 = new byte[imageSize2];
        int len = files.length - imageSize2;
        int j = 0;
        for (int i = len; i < files.length; i++) {
            file2[j] = files[i];
            j++;
        }
        return file2;
    }

}
